<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Grid {

	private $id = '';
	private $size = 3;
	private $konten;
	private $alpha = false;
	private $omega = false;
	private $class;

	public function __construct($size = 3, $alpha = false, $omega = false, $id = ''){
		$this->CI =& get_instance();
		$this->size = $size;
		$this->alpha = $alpha;
		$this->omega = $omega;
		$this->id = $id;
	}

	public function set_alpha($alpha){
		$this->alpha = $alpha;
		return $this;
	}

	public function set_omega($omega){
		$this->omega = $omega;
		return $this;
	}

	public function set_class($class){
		$this->class = $class;
		return $this;
	}

	public function add_clear(){
		$this->konten[] = "<div class='clear'></div>";
		return $this;
	}

	public function add_custom($tag,$isi,$id = '' ,$tambahan = ''){

		if($id != '')
			$id = "id = '$id'";

		$data = "<$tag $id $tambahan> $isi </$tag>";

		$this->konten[] = $data;
		return $this;
	}

	public function add_info($info,$img = ''){
		$data = '';

		if($img != '')
			$data .= img($img);

		$data .= "<p>$info</p>";

		$data .= "<div class='clear'></div>";

		$this->konten[] = $data;

		return $this;
	}
	
	public function add_grid($grid = 3, $alpha = false, $omega = false){

		if(is_int($grid)){
			$grid = new Grid($grid,$alpha,$omega);
		} 

		if(is_object($grid)){
			if(get_class($grid) == 'Grid'){
				$this->konten[] = $grid;
			}
		} else return false;

		return $grid;

	}

	public function add_nama_info($akun,$img = ''){
		$kelas = get_class($akun);
		$kelas = strtolower(substr($kelas,7));

		if($kelas == 'speedy')
			$id = $akun->get_id();
		else $id = $akun->get_username();

		if($kelas == 'perusahaan'){
			$kelas = 'customer';
		}

		$data = '';

		if($img != '')
			$data .= img($img);

		$data .= heading(anchor("$kelas/detail/$id",$akun->get_nama()),4);
		$data .= "<div class='clear'></div>";

		$this->konten[] = $data;

		return $this;
	}

	public function add_blockquote($cite,$isi,$link){

		$data = "
			<blockquote> <p>$isi</p> </blockquote>
			<cite title='$link'> $cite <span>$link</span> </cite>
			<div class='arrow'></div>
			";

		$this->konten[] = $data;

		return $this;
	}

	public function __toString(){

		if($this->alpha) 
			$alpha = 'alpha';
		else $alpha = '';

		if($this->omega) 
			$omega = 'omega';
		else $omega = '';

		if($this->id != '')
			$id = "id = '$this->id'";
		else $id = '';

		$string = "<div class='grid_$this->size $alpha $omega $this->class' $id>";

		if($this->konten){
			foreach($this->konten as $isi){
				$string .= $isi;
			}
		}

		$string .= "</div>";

		return $string;
	}

}
